import { resetRouter, routes } from '@/router'
import { defineStore } from 'pinia'
import { ref } from 'vue'
import type { RouteRecordRaw } from 'vue-router'

export const useMenuStore = defineStore('menu', () => {
  // 定义初始的静态菜单列表
  const menuList = ref<RouteRecordRaw[]>([...routes])

  // 将动态筛选的菜单列表保存到 menuList 中
  const setMenuList = (list: RouteRecordRaw[]) => {
    menuList.value = [...menuList.value, ...list]
  }

  //重置菜单列表
  const resetMenuList = () => {
    menuList.value = [...routes]
    resetRouter()
  }

  return {
    menuList,
    setMenuList,
    resetMenuList
  }
})
